﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KPIS.GERP.GAMS.APP.App_UI.Commons;
using KPIS.GERP.GAMS.DAL;

namespace KPIS.GERP.GAMS.APP.App_UI.Forms
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                HttpCookie cookie = Request.Cookies["UserDetail"];
                if (cookie != null && 
                    !string.IsNullOrEmpty(cookie["EmpSeq"]) && 
                    Convert.ToString(Session["EmpSeq"]) != Convert.ToString(cookie["EmpSeq"]))
                {
                    var data = new D_SECURITY_Users().GetUserInfo(null, null, Convert.ToInt32(cookie["EmpSeq"])).Rows;
                    foreach(DataRow dr in data)
                    {
                        if (Convert.ToString(dr["emp_seq"]) != Convert.ToString(cookie["EmpSeq"])) continue;
                        Session["UserName"] = dr["USER_NAME"] as string; //cookie["UserName"];
                        break;
                    } 
                    Session["EmpSeq"] = cookie["EmpSeq"];
                    Session["UserJobsiteSeq"] = cookie["WorkingJobSiteSeq"];
                    Session["UserInternalJobsiteSeq"] = cookie["WorkingJobSiteSeq"];
                    Session["UserWorkAreaSeq"] = null;
                    Session["Height"] = cookie["Height"];
                }
               
            }
        }
    }
}